package com.base.ane;

import java.util.HashMap;
import java.util.Map;

import android.util.Log;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;

public class BaseContext extends FREContext {

	public static final String FUNCTION_INIT = "base_function_init";
	public static final String FUNCTION_LOGIN = "base_function_login";
	public static final String FUNCTION_PAY = "base_function_pay";
	public static final String FUNCTION_EXIT = "base_function_exit";
	
	@Override
	public void dispose() {
	}

	@Override
	public Map<String, FREFunction> getFunctions() {
		Map<String, FREFunction> funMap = new HashMap<String, FREFunction>();
		// 映射
		funMap.put(FUNCTION_INIT, new InitFun());
		funMap.put(FUNCTION_LOGIN, new LoginFun());
		funMap.put(FUNCTION_PAY, new PayFun());
		funMap.put(FUNCTION_EXIT, new ExitFun());
		return funMap;
	}
}

class InitFun implements FREFunction{

	private String TAG = "InitFun";
	private FREContext _context;
	
	@Override
	public FREObject call(FREContext cxt, FREObject[] args) {
		FREObject result = null;
		_context = cxt;
		Log.d(TAG, "---------初始化返回-------");
		_context.dispatchStatusEventAsync(TAG, "初始化回调: success");
		return result;
	}
}

class LoginFun implements FREFunction{
	
	private String TAG = "LoginFun";
	private FREContext _context;
	
	@Override
	public FREObject call(FREContext cxt, FREObject[] args) {
		FREObject result = null;
		_context = cxt;
		Log.d(TAG, "---------Login返回-------");
		_context.dispatchStatusEventAsync(TAG, "Login回调: success");
		return result;
	}
}

class PayFun implements FREFunction{
	
	private String TAG = "PayFun";
	private FREContext _context;
	
	@Override
	public FREObject call(FREContext cxt, FREObject[] args) {
		FREObject result = null;
		_context = cxt;
		Log.d(TAG, "---------Pay返回-------");
		_context.dispatchStatusEventAsync(TAG, "Pay回调: success");
		return result;
	}
}

class ExitFun implements FREFunction{
	
	private String TAG = "ExitFun";
	private FREContext _context;
	
	@Override
	public FREObject call(FREContext cxt, FREObject[] args) {
		FREObject result = null;
		_context = cxt;
		Log.d(TAG, "---------Exit返回-------");
		_context.dispatchStatusEventAsync(TAG, "Exit回调: success");
		return result;
	}
}